/*
 * @Author: sparkstudiosju 419785598@qq.com
 * @Date: 2025-08-28 23:38:43
 * @LastEditors: sparkstudiosju 419785598@qq.com
 * @LastEditTime: 2025-08-29 01:38:30
 * @FilePath: /SJUDEMO_HAL/src/led.c
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
 */
#include "led.h"

/**
 * @brief LED初始化
 * @param None
 * @retval None
 */
void LED_Init(void) {
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    
    // 使能GPIOC时钟（LED1, LED2, LED3）
    __HAL_RCC_GPIOC_CLK_ENABLE();
    
    // 使能GPIOB时钟（LED4）
    __HAL_RCC_GPIOB_CLK_ENABLE();
    
    // 配置LED1, LED2, LED3引脚
    GPIO_InitStruct.Pin = LED1_PIN | LED2_PIN | LED3_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);
    
    // 配置LED4引脚
    GPIO_InitStruct.Pin = LED4_PIN;
    HAL_GPIO_Init(LED4_GPIO_PORT, &GPIO_InitStruct);
    
    // 关闭所有LED
    LED1_OFF(); LED2_OFF(); LED3_OFF(); LED4_OFF();
}

/**
 * @brief 统一LED控制接口（用于批量控制）
 * @param led_num: LED序号 (0-3)
 * @param state: LED状态 (0:关闭, 1:点亮)
 * @retval None
 */
void LED_Control(int led_num, int state) {
    // 参数检查
    if (led_num < 0 || led_num > 3) {
        return;
    }
    
    // 根据序号和状态控制LED
    switch (led_num) {
        case 0:  // LED1
            state ? LED1_ON() : LED1_OFF();
            break;
        case 1:  // LED2
            state ? LED2_ON() : LED2_OFF();
            break;
        case 2:  // LED3
            state ? LED3_ON() : LED3_OFF();
            break;
        case 3:  // LED4
            state ? LED4_ON() : LED4_OFF();
            break;
        default:
            break;
    }
}
